package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.TransportPurchaseDetail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * created by wangjunfu on 2021-02-24 15:59:48
 */
@Repository
public class TransportPurchaseDetailDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(TransportPurchaseDetailDao.class);

    public TransportPurchaseDetail insert(final TransportPurchaseDetail transportPurchaseDetail) {
        insert("TransportPurchaseDetail.insert", transportPurchaseDetail);
        return transportPurchaseDetail;
    }

    public Boolean updateInfoById(final TransportPurchaseDetail transportPurchaseDetail) {
        return update("TransportPurchaseDetail.updateInfoById", transportPurchaseDetail) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("TransportPurchaseDetail.updateInfoByQuery", query) > 0;
    }

    public TransportPurchaseDetail selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("TransportPurchaseDetail.selectById", query);
    }

    public List<TransportPurchaseDetail> selectByQuery(final Query query) {
        return queryForList("TransportPurchaseDetail.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("TransportPurchaseDetail.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        TransportPurchaseDetail transportPurchaseDetail = new TransportPurchaseDetail();
        transportPurchaseDetail.setDeleteFlag(1);
        transportPurchaseDetail.setId(id);
        transportPurchaseDetail.setEntId(entId);

        return update("TransportPurchaseDetail.updateInfoById", transportPurchaseDetail) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("TransportPurchaseDetail.deleteById", query) > 0;
    }

    /**
     * 获取配件的库存数量
     * 以 Map 的形式返回结果
     *
     * @param query
     * @return
     */
    public List<Map<String, String>> selectSumCount(final Query query, final String element) {
        return queryForList("TransportPurchaseDetail." + element, query);
    }
}